
'''	
	This file is part of Roseena.
	
	Copyright (C) 2008	Mohamed Hazem <mohamed.hazem@student.guc.edu.eg>
	Copyright (C) 2008	Mostafa Hany <mostafa.hany@student.guc.edu.eg>

	
	Roseena is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Roseena is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Roseena.	If not, see <http://www.gnu.org/licenses/>.
'''

from PyQt4.QtGui import QWidget, QPlainTextEdit, QFont, QApplication
from PyQt4.QtCore import SIGNAL
from PyQt4.QtNetwork import QHostAddress
from MainServer import MainServer
import sys

HOST = QHostAddress(QHostAddress.LocalHost)
PORT = 8001
SIZEOF_UINT16 = 2

class MainServerWindow(QWidget):
	'''
	Server's Window class.
	'''

	def __init__(self):
		'''
		Constructor
		'''
		app = QApplication(sys.argv)

		QWidget.__init__(self)

		self.mainServer = MainServer(HOST, PORT)
		self.connect(self.mainServer, SIGNAL("newConnection()"), self.gotConnection)

		self.setGeometry(450, 200, 400, 400)
		self.setFixedSize(400, 400)

		font = QFont()
		font.setBold(True)

		self.infoArea = QPlainTextEdit(self)
		self.infoArea.resize(400, 400)
		self.infoArea.setReadOnly(True)
		self.infoArea.setFont(font)

		self.infoArea.appendPlainText("Main Server Listening: " + str(self.mainServer.isListening()))
		self.infoArea.appendPlainText("Port: " + str(self.mainServer.serverPort()))
		self.infoArea.appendPlainText("Listening on connections from: " + str(self.mainServer.serverAddress().toString()))

		self.setWindowTitle("Main Server")
		self.show()

		sys.exit(app.exec_())

	def gotConnection(self):
		self.infoArea.appendPlainText("Incoming Connection")
